# Audio Module
# i2s is the name of the audio hardware itself.

# i think this fills the buffer
# on that note, lets call this audio_fill
audio_fill:
	lw $t6, 0($t0)	#i2s position
	subu $t6, $t6, $t4
	andi $t6, $t6, 0x03ff #free space
	
# surely, this must then play the audio
# as such, lets call this audio_play
audio_play:
	# if the buffer is empty, refill it
	beq $t6, $zero, audio_fill
	nop

	addu $s0, $t1, $t2	#audio data to grab
	beq $s0, $t3, start
	nop
	addu $s1, $t5, $t4	#location in the buffer to write to
	lw $s2, 0($s0)
	sw $s2, 0($s1)
	addiu $t2, $t2, 4
	addiu $t4, $t4, 4
	andi $t4, $t4, 0x03ff
	addiu $t6, $t6, -4

	j audio_play
	nop	
